package com.kancy.demo.delay.queue.redis.handler;

import com.kancy.delay.queue.redis.handler.DelayQueueMessageHandler;
import com.kancy.delay.queue.redis.handler.EmptyDelayQueueMessageHandler;
import com.kancy.delay.queue.redis.message.DelayMessage;
import com.kancy.delay.queue.redis.properties.DelayQueueProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * TestRetryDelayQueueMessageHandler
 * <p>
 *
 * @author: kancy
 * @date: 2020/3/5 22:07
 **/
@RequiredArgsConstructor
@Component
public class TestRetryDelayQueueMessageHandler implements DelayQueueMessageHandler {
    private final DelayQueueProperties delayQueueProperties;
    private final EmptyDelayQueueMessageHandler emptyDelayQueueMessageHandler;
    /**
     * 处理延迟消息
     *
     * @param delayMessage
     */
    @Override
    public void process(DelayMessage delayMessage) {
        if (delayMessage.getRetry() < delayQueueProperties.getTopics().get(delayMessage.getTopic()).getMaxRetry() -1){
            throw new RuntimeException("测试异常");
        }
        emptyDelayQueueMessageHandler.process(delayMessage);
    }
}
